package org.jiopi.ibean.kernel.context;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.jiopi.framework.FrameworkInitializer;
import org.jiopi.ibean.example.blueprint.testblueprint.ClassControlPanel;
import org.jiopi.ibean.sample.MyCar;
import org.jiopi.ibean.sample.MyClassControlPanel2;
import org.junit.BeforeClass;
import org.junit.Test;
import star.trek.voyager.blueprint.car.Car;

public class RedefineTestCase {
	
	@BeforeClass public static void init(){
		FrameworkInitializer.initialize();
	}
	
	@Test public void test_ContextRedefine() throws Exception{
		{//POJO Style My Impl
			ClassLoader cl = Thread.currentThread().getContextClassLoader();
			Class<?> MyClassControlPanel = cl.loadClass("org.jiopi.ibean.sample.MyClassControlPanel");
			ClassControlPanel ccp = (ClassControlPanel)MyClassControlPanel.getConstructor(new Class<?>[]{}).newInstance();
//			ClassControlPanel ccp = new MyClassControlPanel();
			assertEquals("classMethod in NewInterfaceAndClassControlPanelImpltrue",ccp.classMethod());
			assertEquals("staticClassMethod in NewInterfaceAndClassControlPanelImpl",ccp.getClass().getMethod("staticClassMethod", new Class<?>[]{String.class}).invoke(null, "aaa"));
			assertEquals("classStaticString",ccp.getClass().getField("classStaticString").get(null));
			assertEquals("redefineClassStaticString",ccp.getClass().getField("redefineClassStaticString").get(null));
			Car car = new MyCar();
			assertNotNull(car);
		}
	}
	@Test public void test_ContextRedefineSpec() throws Exception{
		{
			ClassControlPanel ccp = new MyClassControlPanel2();
			assertEquals("classMethod in NewInterfaceAndClassControlPanelImpltrue",ccp.classMethod());
			assertEquals("staticClassMethod in NewInterfaceAndClassControlPanelImpl",MyClassControlPanel2.staticClassMethod("aaa"));
			assertEquals("classStaticString",MyClassControlPanel2.classStaticString);
			assertEquals("redefineClassStaticString",MyClassControlPanel2.redefineClassStaticString);
		}
	}
}
